package Servlet;
/*
@ClassName:     Servlet_Login
@Author:        YangXu
@Need:          
@Date:          2022/4/27
@Time:          2022-04-27 9:55
*/

//



import entity.User;
import service.UserService;
import service.UserServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login")
public class Servlet_Login extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset-utf-8");
        resp.setHeader("content-type","text/html;charset=utf-8");
        String username = req.getParameter("account");
        String password = req.getParameter("password");
        UserService userServiceImp = new UserServiceImp();
        User user = userServiceImp.findUser(username, password);
        System.out.println("前端传给的账号："+username);
        System.out.println("前端传给的密码："+password);
        System.out.println("------------");
        if (user!=null) {
                resp.sendRedirect("./userManage/UserList");
        } else{
            resp.sendRedirect("404.html");
        }
    }
}
/*

 */